package com.sas.repository;

import com.sas.entity.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 员工Repository接口
 */
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {

    /**
     * 根据状态查询员工
     */
    List<Employee> findByStatus(Integer status);

    /**
     * 根据员工类型查询员工
     */
    List<Employee> findByEmployeeType(Integer employeeType);

    /**
     * 根据员工类型和状态查询员工
     */
    List<Employee> findByEmployeeTypeAndStatus(Integer employeeType, Integer status);

    /**
     * 根据姓名模糊查询员工
     */
    List<Employee> findByNameContaining(String name);

    /**
     * 根据薪资等级查询员工
     */
    List<Employee> findBySalaryLevel(Integer salaryLevel);

    /**
     * 查询在职员工按员工类型排序（全职优先）
     */
    @Query("SELECT e FROM Employee e WHERE e.status = 1 ORDER BY e.employeeType ASC, e.salaryLevel DESC")
    List<Employee> findActiveEmployeesOrderByTypeAndLevel();

    /**
     * 根据工作时长范围查询员工
     */
    @Query("SELECT e FROM Employee e WHERE e.workHoursPerWeek >= :minHours AND e.workHoursPerWeek <= :maxHours AND e.status = 1")
    List<Employee> findByWorkHoursRange(@Param("minHours") Integer minHours, @Param("maxHours") Integer maxHours);

    /**
     * 根据员工类型列表和状态查询员工（用于排班算法）
     */
    @Query("SELECT e FROM Employee e WHERE e.employeeType IN :employeeTypes AND e.status = :status")
    List<Employee> findByEmployeeTypeInAndStatus(@Param("employeeTypes") List<Integer> employeeTypes,
                                                 @Param("status") Integer status);
}